﻿/*----------------------------------------------------------------
//  <copyright file="SmsVerifyCodeController.cs" company="MicroCloud@151504200868">
//      Copyright © 2020-2024 MicroCloud Corporation, All rights reserved.
//  </copyright>
//  <site>https://gitee.com/chenmm123/microclouds</site>
//  <last-editor>cmm</last-editor>
//  <last-date>2023-11-22 15:21</last-date>
//----------------------------------------------------------------*/

namespace MicroCloud.Api.SMS.Areas.Admin.Controllers.SMS
{
    #region "验证码短信管理"
    /// <summary>
    /// 验证码短信管理
    /// </summary>
    [Description("验证码短信管理")]
    [ModuleInfo(Code = "SmsVerifyCode", Name = "验证码短信管理", OrderNo = 1, Position = "SMS", PositionName = "短信模块")]
    public class SmsVerifyCodeController : AdminControllerBase
    {
        #region "属性"
        #region "获取 短信验证码服务"
        /// <summary>
        /// 获取 短信验证码服务
        /// </summary>
        protected ISmsVerifyCodeService SmsVerifyCodeService => ServiceProvider.GetService<ISmsVerifyCodeService>();
        #endregion
        #region "获取 验证码短信仓储对象"
        /// <summary>
        /// 获取 验证码短信仓储对象
        /// </summary>
        protected IRepository<VerifyCode, long> VerifyCodeRepository => ServiceProvider.GetService<IRepository<VerifyCode, long>>();
        #endregion
        #region "获取 验证码短信查询数据集"
        /// <summary>
        /// 获取 验证码短信查询数据集
        /// </summary>
        protected IQueryable<VerifyCode> VerifyCodes => VerifyCodeRepository.QueryAsNoTracking();
        #endregion

        #endregion

        #region "Action方法"
        #region "读取验证码短信"
        /// <summary>
        /// 读取验证码短信
        /// </summary>
        /// <param name="request">分页请求</param>
        /// <returns>验证码短信记录</returns>
        [HttpPost]
        [ModuleInfo]
        [Description("读取")]
        public virtual async Task<PageData<VerifyCodeOutputDto>> Read(PageRequest request)
        {
            Check.NotNull(request, nameof(request));
            IFunction function = this.GetExecuteFunction();

            Expression<Func<VerifyCode, bool>> predicate = FilterService.GetExpression<VerifyCode>(request.FilterGroup);

            var page = CacheService.ToPageCache(VerifyCodes, predicate, request.PageCondition, m => new VerifyCodeOutputDto()
            {
                Id = m.Id,
                Provider = m.Provider,
                SignName = m.SignName,
                TemplateCode = m.TemplateCode,
                BizId = m.BizId,
                RequestId = m.RequestId,
                OutId = m.OutId,
                PhoneNumber = m.PhoneNumber,
                SendDate = m.SendDate,
                ReceiveDate = m.ReceiveDate,
                ExpireMins = m.ExpireMins,
                Verified = m.Verified,
                VerifiedTime = m.VerifiedTime,
                CreatedTime = m.CreatedTime,
            }, function);
            return await Task.FromResult(page.ToPageData());
        }
        #endregion

        #endregion

    }
    #endregion

}
